﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>SysGetIPAddresses - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The SysGetIPAddresses function returns an array of the system's IPv4 addresses." />
<meta name="ahk:equiv-v1" content="Variables.htm#IPAddress" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>SysGetIPAddresses</h1>

<p>返回系统的 IPv4 地址数组.</p>

<pre class="Syntax">Addresses := <span class="func">SysGetIPAddresses</span>()</pre>

<h2 id="Parameters">参数</h2>
<p>此函数没有参数.</p>

<h2 id="Return_Value">返回值</h2>
<p>类型: <a href="../Concepts.htm#strings">字符串</a><a href="../Concepts.htm#objects">数组</a></p>
<p>函数返回一个数组, 其每个元素是 IPv4 地址字符串, 如 "192.168.0.1".</p>

<h2 id="Remarks">备注</h2>
<p>目前仅支持 IPv4.</p>
<p>此函数仅返回计算机网络适配器的 IP 地址. 如果计算机通过路由器连接到 Internet, 这将不包括计算机的公共(Internet) IP 地址. 要确定计算机的公共 IP 地址, 请使用外部 web API. 例如:</p>
<pre>whr := ComObject("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", "https://api.ipify.org")
whr.Send()
MsgBox "Public IP address: " whr.ResponseText</pre>

<h2 id="Related">相关</h2>
<p><a href="../Variables.htm#ComputerName">A_ComputerName</a></p>

<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a class="ex_number" href="#ExBasic"></a> 检索并报告系统的 IPv4 地址.</p>
<pre>addresses := SysGetIPAddresses()
msg := "IP addresses:`n"
for n, address in addresses
    msg .= address "`n"
MsgBox msg</pre>
</div>

</body>
</html>